<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>董胜烨第三次作业</title>
    <link rel="stylesheet"
          href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css">
    <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
    <script>hljs.highlightAll();</script>
</head>
<body>
<pre><code class="python">from datetime import datetime
from functools import wraps


def log_it(logfile='out.log'):
    def logging_decorator(func):
        @wraps(func)
        def wrapped_function(*args, **kwargs):
            log = f"[{datetime.now()}] {func.__name__} was called"
            # 打开logfile，并写入内容
            with open(logfile, 'a') as fd:
                # 现在将日志打到指定的logfile
                fd.write(log + '\n')
            return func(*args, **kwargs)
        return wrapped_function
    return logging_decorator


@log_it()
def my_func1():
    pass


@log_it(logfile='func2.log')
def my_func2():
    pass


my_func1()
my_func2()</code></pre>


<script>

</script>
</body>
</html>